"""

多行注释
"""

'''
多行注释

快捷键：Ctrl + / 
'''

# 单行注释

# applePrice = 1
# bananaPrice = 8
# pearPrice = 7

# 换行
# total = applePrice + \
#     bananaPrice + \
#     pearPrice
# print(total)
# 换行
# total2 = [applePrice,
#          bananaPrice,
#          pearPrice]

# print(total2)

# 正确缩进形式

# A = 2
# if A :
#     print("我的行缩进空格数相同")
# else:
#     print("我的行缩进空格数相同")

# and = '我是保留字' # 以保留字作为变量名出错

# strExample = 'asfasf'  # 创建一个字符串变量
# print(len(strExample))  # 使用len函数查看字符串长度
# len = 'wetag'  # 使用len作为变量名
# print(len)
# print(len(strExample))  # len函数查看字符串长度出错

#一个值同时赋给多个变量
# a = b = c = 1
# print(a)
# print(b)
# print(c)
# print(type(c))
#
# #多个值赋给多个变量
# a,b,c = 1, 2, 'abc'
# print(a)
# print(b)
# print(c)
# print(type(c))
#
# # 浮点型转整型
# print(int(1.56))
# print(int(0.156))
# print(int(-1.56))
# print(int())
#
# # 布尔型转整型
# print(int(True))
# print(int(False))
#
# # 复数转整型
# print(int(1+23))

# # 整型转布尔型
# print(bool(1))
# print(bool(2))
# print(bool(0))
# #
# # 浮点型转布尔型
# print(bool(1.0))
# print(bool(2.3))
# print(bool(0.3))
# print(bool(-0.3))
# print(bool(0.0))
#
# # 复数转布尔型
# print(bool(1+23j))
# print(bool(23j))
#
# # 各种类型的空值转布尔型
# print(bool())
# print(bool(''))
# print(bool([]))
# print(bool(()))
# print(bool({}))


#三引号的使用
print('''\
This is the first sentence.
This is the second sentence.
This is the third sentence.''')
print('\
This is the first sentence.
This is the second sentence.
This is the third sentence.')
print("\
This is the first sentence.
This is the second sentence.
This is the third sentence.")

#提取指定位置的字符
word = 'Python'
print(word[1])  # 提取第二个字符
print(word[0])  # 提取第一个字符
print(word[-1])  # 提取最后一个字符

print(word[0:3])  # 截取第 1~3 个字符'Pyt’
print(word[:3])  # 取第1~3个字符"Pyt"
print(word[4:])  # 截取第5到最后一个字符'on'

print(word[3:52])  # 第二个崇引越界'hon'
print(word[52:])  # 第一个索引超出字符串长度''
print(word[-1:3])  # 第一个索引为负，第二个索引正常''
print(word[5:3])  # 第一个索引大于第二个索引''

#字符串拼接
print('Python is' + 3 * ' good')  # 加号拼接字符串
print('Python is' ' good')  # 相邻字符串自然拼接

#将字符串“Life is short,you need something.”修改成“Life is short,you need Python.”
sentence = 'Life is short,you need something.'
print(sentence[:23] + 'Python.')
print(sentence[:14] + 'i' +sentence[17:])

#字符类型字符串格式化
print("我叫 %s 今年 %d 岁" %('小明',10))

#通过{}来代替%
print('{} a word she can get what she {} for.'.format('With','came'))

#通过关键字参数
print('{pre} a word she can get what she {verb}    for.'.format(pre='With',verb='came'))

#通过位置
print('{0} a word she can get what she {1} for.'.format('With','came'))

#通过下标索引
p = ['With','came']
print('{0[0]} a word she can get what she {0[1]} for.'.format(p))

applePriceStr = 'Apple\'s unit price is 9 yuan.'
applePrice = applePriceStr[22]  # 提取数值
print('提取了苹果的单价为：', applePrice, '。此刻它的数据类型为：', type(applePrice))
applePrice = int(applePrice)  # 转换为整型
print('转换数据类型后：', type(applePrice))